package com.xiaojie.toolkits;

import cn.hutool.core.util.StrUtil;
import com.xiaojie.context.DataInfoContext;
import com.xiaojie.parse.model.DataModel;
import com.xiaojie.parse.model.Settings;
import org.apache.commons.lang3.StringUtils;

/**
 * @ClassName FieldNameUtil
 * @Description 字段根据配置转换为下划线或驼峰
 * @Author wangye
 * @Date 2023/3/22
 **/
public class FieldNameUtil {

    /**
     * 字段根据配置转换为下划线或驼峰
     *
     * @param fieldName
     * @Author: wangye
     * @Date: 2023/3/22 13:19
     * @return:
     **/
    public static String convert(String fieldName) {

        DataModel dataModel = DataInfoContext.get().getDataModelInfo();
        return convert(fieldName, dataModel.getSettings());
    }

    public static String convert(String fieldName, Settings settings) {

        if (StringUtils.isBlank(fieldName)) {
            return fieldName;
        }
        boolean isCamelCasefieldName = settings != null ? settings.getFieldNameIsCamelCase() : false;
        return isCamelCasefieldName ? StrUtil.toCamelCase(fieldName) : StrUtil.toUnderlineCase(fieldName);
    }


}
